﻿@model Xms.Web.Models.EmailSettingModel
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            <a data-toggle="collapse"
               href="#collapseTwo">
                <strong>@app.PrivilegeTree?.LastOrDefault().DisplayName</strong>
            </a>
        </h3>
    </div>
    <div class="panel-body">
        <form id="editform" class="form-horizontal" data-jsonajax="true" data-istip="true" action="/@(app.OrganizationUniqueName)/api/settings/email" method="post">
            <div class="form-group col-sm-12">
                @Html.LabelFor(x => x.Host, "主机", new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.Host, new { @class = "form-control required" })
                </div>
            </div>
            <div class="form-group col-sm-12">
                @Html.LabelFor(x => x.Port, "端口", new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.Port, new { @class = "form-control", @data_type = "int" })
                </div>
            </div>
            <div class="form-group col-sm-12">
                @Html.LabelFor(x => x.UserName, "帐号", new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.UserName, new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group col-sm-12">
                @Html.LabelFor(x => x.Password, "密码", new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.PasswordFor(x => x.Password, new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group col-sm-12">
                @Html.LabelFor(x => x.From, "发送邮箱", new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.From, new { @class = "form-control", @data_type = "email" })
                </div>
            </div>
            <div class="form-group col-sm-12">
                @Html.LabelFor(x => x.FromName, "发送者名称", new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.FromName, new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group col-sm-12">
                <div class="col-sm-offset-2 col-sm-10">
                    <button class="btn btn-info btn-xs" type="button" onclick="addRow(this)">增加一条内容</button>
                </div>
            </div>
            <div class="form-group col-sm-12">
                <label class="col-sm-2 control-label" for="contents">内容</label>
                <div class="col-sm-10">
                    <table class="table" id="contents">
                        <thead>
                            <tr><th class="col-sm-2">名称</th><th class="col-sm-10">内容</th></tr>
                        </thead>
                        <tbody>
                            @if (Model.Bodies != null)
                            {
                                foreach (var item in Model.Bodies)
                                {
                                    <tr>
                                        <td>
                                            <input type="text" name="name" class="form-control" value="@item.Name" />
                                        </td>
                                        <td>
                                            <input type="text" name="content" class="form-control" value="@item.Content" />
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="form-group col-sm-12 text-center" id="form-buttons">
                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-saved"></span> @app.T["save"]</button>
                <button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> @app.T["reset"]</button>
            </div>
        </form>
    </div>
</div>

@section Scripts {
    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-validate/jquery.validate.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script src="/content/js/jquery-validate/localization/messages_zh.min.js?v=@app.PlatformSettings.VersionNumber"></script>
    <script>
        $(function () {
            //表单验证
            var $form = $("#editform");
            Xms.Web.Form($form, function (response) {
                console.log(response);
                //Xms.Web.Toast(response.Content, response.IsSuccess);
            });
        });
        function addRow(e) {
            var row = [];
            row.push('<tr>');
            row.push('<td><input class="form-control" name="name" /></td>');
            row.push('<td>');
            row.push('<input type="text" class="form-control" name="content" />');
            row.push('</td>');
            row.push('</tr>');
            $('#contents tbody').append($(row.join('')));
        }
    </script>
}